﻿
namespace SomethingSpacialClassLib.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.Server;
    using System.ServiceModel.DomainServices.EntityFramework;


    // Implements application logic using the SUGWTKEntities1 context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    public partial class SomethingSpacialService : LinqToEntitiesDomainService<SUGWTKEntities1>
    {

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<UserGroup> GetUserGroups()
        {
            return this.ObjectContext.UserGroups;
        }

        public IQueryable<UserGroup> GetUserGroupsFirst()
        {
            return this.ObjectContext.UserGroups.OrderByDescending(e => e.UG_Id).Take(1);
        }


        public void InsertUserGroup(UserGroup userGroup)
        {
                if ((userGroup.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(userGroup, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.UserGroups.AddObject(userGroup);
                }
         
        }

        public void UpdateUserGroup(UserGroup currentUserGroup)
        {
            if ((currentUserGroup.EntityState == EntityState.Detached))
            {
                this.ObjectContext.UserGroups.AttachAsModified(currentUserGroup, this.ChangeSet.GetOriginal(currentUserGroup));
            }
        }

        public void DeleteUserGroup(UserGroup userGroup)
        {
            if ((userGroup.EntityState == EntityState.Detached))
            {
                this.ObjectContext.Attach(userGroup);
            }
            this.ObjectContext.UserGroups.DeleteObject(userGroup);
        }
    }
}


